<?php
/**
 * Css.php
 *
 * 视图CSS样式表载入助手
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://momoger.com/license
 *
 * @category	Momoger
 * @package 	Momoger_View
 * @subpackage 	Helper
 * @author 		Guya
 * @version    	1.0
 * @copyright  	Copyright © 2009 www.momoger.com All Rights Reserved.
 * @license    	http://momoger.com/license     New BSD License
 */

/** Zend_View_Helper_Abstract */
//require_once 'Zend/View/Helper/Abstract.php';

/**
 * 视图CSS助手类
 *
 * @category 	Momoger
 * @package		Momoger_View
 * @subpackage 	Helper
 * @copyright  	Copyright © 2009 www.momoger.com All Rights Reserved.
 * @license    	http://momoger.com/license     New BSD License
 */
class Momoger_View_Helper_Css extends Zend_View_Helper_Abstract {
    /**
     * 用来保存发送的CSS样式文件名
     *
     * @var array
     */
    protected $_sheets = array();

    /**
     * 设定基本路径
     *
     * @var string
     */
    protected $_baseDir = 'default';

    /**
     * 获取自身对象
     *
     * @param string $base_dir 基本路径
     * @return Momoger_View_Helper_Css
     */
    public function css($base_dir = 'default') {
    	$this->_baseDir = $base_dir;
        return $this;
    }

    /**
     * 追加一条记录到最后
     *
     * @param string $value css 样式文件名
     * @return Momoger_View_Helper_Css
     */
    public function append($value) {
        array_push($this->_sheets, $value);
        return $this;
    }

    /**
     * 追加一条记录到最前
     *
     * @param string $value css 样式文件名
     * @return Momoger_View_Helper_Css
     */
    public function prepend($value) {
        array_unshift($this->_sheets, $value);
        return $this;
    }

    /**
     * 返回所有的页面需求样式文件
     *
     * @return string
     */
    public function __toString() {
        if (count($this->_sheets)) {
            $href = '/styles/getStyles.php?';
            $i = 0;
            foreach ($this->_sheets as $item) {
                $i++;
                $href .= 'c' . $i . '=' . $this->_baseDir . '/' . $item . '&';
            }
            return '<link rel="stylesheet"  rev="stylesheet" type="text/css" href="' . substr($href,0, -1) . '" />';
        }
        return '';
    }
}